<template>
  <Popup
    v-model:show="showPopup"
    :style="{ background: 'transparent', overflow: 'hidden' }"
  >
    <div class="sign-in-box">
      <div class="sign-in-top-box">
        <div class="sign-in-heard">{{ heardText }}</div>
      </div>
      <div v-if="!isSign" class="sign-in-body-box">
        <div class="sign-in-body-title">今日签到获得10金币</div>
        <div class="sign-in-body-title-time">
          {{ dayjs().format("M月DD日") }}
        </div>
        <div class="hexagon-flex-box">
          <div
            v-for="item in signList"
            :key="item.name"
            :class="{
              'hexagon-box': item.taskStatus == 1,
              'hexagon-box-active': item.taskStatus == 3,
            }"
          >
            <div class="nexagon-number">{{ item.name }}</div>
            <div class="nexagon-day">DAY</div>
            <div class="nexagon-gold">金币+ {{ item.goldCoins }}</div>
            <img src="@/assets/image/gold.png" class="gold" />
          </div>
        </div>
        <div class="sign-in-button" v-if="childrenTaskId" @click="signClick">
          签到
        </div>
      </div>
      <div v-else class="signed-in-successfully">
        <div class="signed-in-successfully-box">
          <div class="successfully-title">签到成功</div>
          <img
            src="@/assets/image/successfully.png"
            class="successfully-image"
          />
          <div class="successfully-title-bottom">
            经验+{{ signList[childrenTaskIndex].experience }} 金币+{{
              signList[childrenTaskIndex].goldCoins
            }}
          </div>
        </div>
      </div>
      <img
        src="@/assets/image/transparent-background.png"
        class="transparent-background"
      />
      <img
        src="@/assets/image/gradient-background.png"
        class="gradient-background"
      />
      <img src="@/assets/image/panda.png" class="panda" />
      <img src="@/assets/image/star.png" class="star" />
      <img
        src="@/assets/image/close.png"
        @click="closeClick"
        class="close-image"
      />
    </div>
  </Popup>
</template>
<script lang="ts" setup>
import { completeTask, getSignIn } from "@/api/common";
import { useMainStore } from "@/store";
import dayjs from "dayjs";
import { Popup, showToast } from "vant";
import { computed, ref, watch } from "vue";
interface signListType {
  /*任务记录id */
  taskRecordId: number;
  /*学生id */
  studentId: number;
  /*任务id */
  taskId: number;
  /*任务类型  <br>  export const GAME_TASK_TYPE_ENUM = <BR> {<br>&nbsp;&nbsp;DAILY_TASKS:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:1,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'日常任务'<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;TIME_LIMITED_TASKS:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:2,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'限时任务'<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;CUSTOMIZED_TASKS:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:3,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'定制任务'<br>&nbsp;&nbsp;}<br>} <br> */
  taskType: number;
  /*附属任务id */
  subTaskId: number;
  /*领取任务时间 */
  claimTaskTime: Record<string, unknown>;
  /*完成任务时间 */
  completeTaskTime: Record<string, unknown>;
  /*领取奖励时间 */
  claimRewardTime: Record<string, unknown>;
  /*完成状态（1去完成，2待领奖，3已领取） */
  taskStatus: number;
  /*类型(1普通任务，2签到，3共育） */
  type: number;
  /*父任务id */
  parentId: number;
  /*任务图片 */
  images: string;
  /*任务名称 */
  name: string;
  /*任务介绍 */
  remark: string;
  /*开始时间 */
  taskBeginTime: Record<string, unknown>;
  /*结束时间 */
  taskEndTime: Record<string, unknown>;
  /*持续天数 */
  durationDays: number;
  /*是否轮询 */
  polling: number;
  /*应用学段集合 */
  stageList: Record<string, unknown>[];
  /* */
  stage: string;
  /*互动逻辑上级  <br>  export const GAME_TASK_INTER_PARENT_ENUM = <BR> {<br>&nbsp;&nbsp;IN_GAME_INTERACTION:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:1,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'游戏内互动'<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;H5_PAGE:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:2,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'H5页面'<br>&nbsp;&nbsp;}<br>} <br> */
  interactionParent: number;
  /*互动逻辑下级  <br>  export const GAME_TASK_INTER_SON_ENUM = <BR> {<br>&nbsp;&nbsp;STROKING_PETS:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:1,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'抚摸宠物'<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;SIGN_IN:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:2,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'签到'<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;POP_UP_NOTIFICATION:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:3,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'弹窗'<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;NEW_PAGE:{<br>&nbsp;&nbsp;&nbsp;&nbsp;value:4,<br>&nbsp;&nbsp;&nbsp;&nbsp;desc:'新页面'<br>&nbsp;&nbsp;}<br>} <br> */
  interactionSon: number;
  /*奖励经验 */
  experience: number;
  /*奖励金币 */
  goldCoins: number;
  /*H5页面地址 */
  pageAddress: string;
  /*上架状态 */
  disabledFlag: boolean;
  /*排序 */
  sort: number;
}
const showPopup = defineModel<boolean>("showPopup");
const signInTask = defineModel<any>("signInTask");
watch(showPopup, (newValue) => {
  if (newValue) {
    getSignInSub();
  }
});
const isSign = ref(false);
const signList = ref<signListType[] | any>();
const childrenTaskId = computed(() => {
  return signList.value?.find(
    (item: { taskId: null | string }) => item.taskId != null
  )?.taskId;
});
const childrenTaskIndex = computed(() => {
  return signList.value?.findIndex(
    (item: { taskId: null | string }) => item.taskId != null
  );
});
function signClick() {
  isSign.value = true;
  const data = {
    studentId: mainStore.studentInfo?.studentId,
    taskId: childrenTaskId.value,
  };
  completeTask(data).then(() => {
    showToast("签到成功");
    mainStore.refreshTask = true;
  });
}
function closeClick() {
  showPopup.value = false;
}
const heardText = ref("今日签到");
const mainStore = useMainStore();
function getSignInSub() {
  const data = {
    studentId: mainStore.studentInfo?.studentId,
    taskId: signInTask.value,
  };
  getSignIn(data).then((res) => {
    signList.value = res.data;
  });
}
</script>
<style lang="scss" scoped>
.sign-in-box {
  width: 340px;
  height: 492px;
  padding: 55px 0 0 0;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  .sign-in-body-box {
    position: relative;
    z-index: 4;
    width: 321px;
    height: 350px;
    top: -26px;
    .sign-in-button {
      margin: 31px auto;
      width: 173px;
      height: 44px;
      border-radius: 100px;
      opacity: 1;
      background: linear-gradient(90deg, #ffc500 0%, #ffb200 100%);
      box-shadow: inset -1px -1px 2px 0px #d89f37,
        inset 1px 1px 2px 0px rgba(255, 255, 255, 0.3);
      display: flex;
      justify-content: center;
      align-items: center;
      font-family: Source Han Sans;
      font-size: 16px;
      font-weight: bold;
      line-height: 28px;
      letter-spacing: 0px;
      font-variation-settings: "opsz" auto;
      color: #ffffff;
      cursor: pointer;
    }
    .sign-in-body-title {
      font-family: Source Han Sans;
      font-size: 18px;
      font-weight: 350;
      line-height: 32px;
      letter-spacing: 0px;
      color: #333333;
      text-align: center;
    }
    .sign-in-body-title-time {
      font-family: Source Han Sans;
      font-size: 14px;
      font-weight: 350;
      line-height: 22px;
      letter-spacing: 0px;
      text-align: center;
      color: #999999;
    }
    .hexagon-flex-box {
      margin: 7px 0 0 0;
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      .hexagon-box {
        width: 68px;
        height: 77px;
        background-image: url("@/assets/image/hexagon-white.png");
        background-size: 100% 100%;
        background-repeat: repeat;
        position: relative;
        .nexagon-gold {
          position: absolute;
          top: 39px;
          left: 12px;
          font-family: Source Han Sans;
          font-size: 12px;
          font-weight: 350;
          line-height: 20px;
          letter-spacing: 0px;
          z-index: 999;
          color: #666666;
        }
        .nexagon-number {
          position: absolute;
          top: 12px;
          left: 12px;
          font-family: Source Han Sans;
          font-size: 24px;
          font-weight: bold;
          line-height: 28px;
          letter-spacing: 0px;
          font-variation-settings: "opsz" auto;
          color: #666666;
        }
        .nexagon-day {
          position: absolute;
          top: 8px;
          left: 28px;
          font-family: Source Han Sans;
          font-size: 14px;
          font-weight: bold;
          line-height: 28px;
          letter-spacing: 0px;
          font-variation-settings: "opsz" auto;
          color: #666666;
        }
        .gold {
          width: 31px;
          height: 31px;
          position: absolute;
          bottom: 13px;
          right: 0;
        }
      }
      .hexagon-box:nth-child(n + 5) {
        margin-top: -18px;
      }
      .hexagon-box-active {
        width: 68px;
        height: 77px;
        background-image: url("@/assets/image/hexagon-gold.png");
        background-size: 100% 100%;
        background-repeat: repeat;
        position: relative;
        .nexagon-gold {
          position: absolute;
          top: 39px;
          left: 12px;
          z-index: 999;
          font-family: Source Han Sans;
          font-size: 12px;
          font-weight: 350;
          line-height: 20px;
          letter-spacing: 0px;
          background: linear-gradient(
            129deg,
            #ffffff 9%,
            rgba(255, 255, 255, 0.3) 94%
          );
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          background-clip: text;
          text-fill-color: transparent;
        }
        .nexagon-number {
          position: absolute;
          top: 12px;
          left: 12px;
          font-family: Source Han Sans;
          font-size: 24px;
          font-weight: bold;
          line-height: 28px;
          letter-spacing: 0px;
          font-variation-settings: "opsz" auto;
          background: linear-gradient(
            161deg,
            #ffffff -7%,
            rgba(255, 255, 255, 0.3) 97%
          );
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          background-clip: text;
          text-fill-color: transparent;
        }
        .nexagon-day {
          position: absolute;
          top: 8px;
          left: 28px;
          font-family: Source Han Sans;
          font-size: 14px;
          font-weight: bold;
          line-height: 28px;
          letter-spacing: 0px;
          font-variation-settings: "opsz" auto;
          background: linear-gradient(
            147deg,
            #ffffff 0%,
            rgba(255, 255, 255, 0.3) 96%
          );
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          background-clip: text;
          text-fill-color: transparent;
        }
        .gold {
          width: 31px;
          height: 31px;
          position: absolute;
          bottom: 13px;
          right: 0;
        }
      }
      .hexagon-box-active:nth-child(n + 5) {
        margin-top: -18px;
      }
    }
  }
  .signed-in-successfully {
    position: relative;
    z-index: 4;
    width: 321px;
    height: 350px;
    top: -26px;
    .signed-in-successfully-box {
      display: flex;
      align-items: center;
      flex-direction: column;
      .successfully-title {
        margin: 20px 0 0 0;
        font-family: Source Han Sans;
        font-size: 28px;
        font-weight: 500;
        line-height: 37.8px;
        letter-spacing: 0px;
        font-variation-settings: "opsz" auto;
        color: #333333;
      }
      .successfully-image {
        margin: 12px 0 0 0;
        width: 89px;
        height: 89px;
      }
      .successfully-title-bottom {
        margin: 29px 0 0 0;
        font-family: Source Han Sans;
        font-size: 14px;
        font-weight: 350;
        line-height: 22px;
        letter-spacing: 0px;
        color: #666666;
      }
    }
  }
  .sign-in-top-box {
    position: relative;
    width: 321px;
    height: 146px;
    background: linear-gradient(90deg, #ffc500 0%, #ffb200 100%);
    border-radius: 20px;
    opacity: 1;
    .sign-in-heard {
      font-family: Source Han Sans;
      font-size: 28px;
      font-weight: bold;
      line-height: 37.8px;
      letter-spacing: 0px;
      font-variation-settings: "opsz" auto;
      color: #ffffff;
      margin: 19px 0 0 18px;
    }
    .sign-in-text {
      font-family: Source Han Sans;
      font-size: 16px;
      font-weight: 500;
      line-height: 28px;
      letter-spacing: 0px;
      font-variation-settings: "opsz" auto;
      color: #ffffff;
      margin: 4px 0 0 18px;
    }
  }
  .close-image {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 9999;
    width: 24px;
    height: 24px;
    background-size: 100% 100%;
    background-repeat: repeat;
  }
  .transparent-background {
    position: absolute;
    z-index: 2;
    top: 136px;
    width: 335px;
    height: 350px;
  }
  .gradient-background {
    position: absolute;
    z-index: 2;
    top: 146px;
    width: 321px;
    height: 330px;
  }
  .panda {
    position: absolute;
    top: 0px;
    right: 4px;
    z-index: 1;
    width: 187px;
    height: 187px;
    background-size: 100% 100%;
    background-repeat: repeat;
  }
  .star {
    position: absolute;
    width: 64px;
    height: 64px;
    background-size: 100% 100%;
    background-repeat: repeat;
    right: -2px;
  }
}
</style>
